using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace SysTables
{


    public class Common
    {
        public static Boolean ContainsEmptyCharacters(string input)
        {
            foreach (char c in input)
                if (char.IsSeparator(c)) return true;
            return false;
        }

        public static int ParseInt(string input)
        {
            int out_i = 0;
            try
            {
                out_i = int.Parse(input);
            }
            catch (ArgumentException e)
            {
                out_i = 0;
                Console.WriteLine(e.Message);
            }
            catch (OverflowException e)
            {
                out_i = 0;
            }
            catch (FormatException e)
            {
                out_i = 0;
                Console.WriteLine(e.Message);
            }
            finally
            {
                
            }
            return out_i;

        }

        public static Boolean ParseBoolean(string input)
        {
            Boolean out_i = false;
            try
            {
                out_i = Boolean.Parse(input);
            }
            catch (ArgumentException e)
            {
                out_i = false;
                Console.WriteLine(e.Message);
            }
            catch (FormatException e)
            {
                out_i = false;
                Console.WriteLine(e.Message);
            }
            return out_i;
        }


        public static byte[] Serialize(Object o)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf1 = new BinaryFormatter();
            bf1.Serialize(ms, o);
            return ms.ToArray();
        }

        public static Object Deserialize(byte[] buffer)
        {

            MemoryStream ms = new MemoryStream(buffer);
            BinaryFormatter bf1 = new BinaryFormatter();
            ms.Position = 0;
            return bf1.Deserialize(ms);
        }

    }
}
